#!/bin/bash

echo "=== 微信支付V3解密测试 ==="

# 设置测试参数
CIPHERTEXT="OqnfGcErZsQ6LdVgBZBlph3Gx77H+Jmcg/z1/JXP37RwKmAAJOOPcS00ZZSGbjiqju6mhG09nBbuoQGqFSwSrBCDtQObxs3xSFxNU4h/3tgy/HzIieEjjxle5d6VYAnREgL6xJyi56x06/iCFe2wcpGwBmq2goN68SJexGLWUTbrhlPnulUhteC++pjgEDba7McHjv4Hi7UMdTwrMIZcJbUZvNjUMf/ikMwRdsCNWNh9rdSyizOF6yWKEAu563xh3PobTNbw5xI+h0p+Lj3W8aOSrvhuHFOmfuG8VvYEZebEAxPRE/Q3Cy47zIXf354sE0GoNQCiL08mlIKrEypz7dK5EZei65ZTxXlRKM+FL6p298UxzyJiVHEKfnF9S17D8S9XXbhVEyL8jsZ338BPC3uGpj/dqpzWpu8mbmlIfFOKV6Wuf/06DOAfT4l3Rr9tNVbrX8BM048JwIsSJIPH8GCA0Q1iMdMRQTfIr1g7o/ccPdp3kKrRLSgfDal3G5L8zYnhPvK4DmQi+dTq6QczbGJ8Rf7WTpUqjkJB0c7Z7yecqcApBgVkvuHlFCErOwexhW59pw=="
ASSOCIATED_DATA="transaction"
NONCE="hEdxtB7iMgLe"
API_V3_KEY="2z7Q9Xp4Rk8Lm3Fb5Gs1Hj6Nv0Tc4Yw2"

echo "测试参数:"
echo "  ciphertext长度: ${#CIPHERTEXT}"
echo "  associatedData: '$ASSOCIATED_DATA'"
echo "  nonce: '$NONCE' (长度: ${#NONCE})"
echo "  apiV3Key长度: ${#API_V3_KEY}"

echo ""
echo "检查参数格式:"

# 检查ciphertext是否为Base64编码
if echo "$CIPHERTEXT" | base64 -d > /dev/null 2>&1; then
    echo "✓ ciphertext是有效的Base64编码"
else
    echo "✗ ciphertext不是有效的Base64编码"
fi

# 检查nonce是否为Base64编码
if echo "$NONCE" | base64 -d > /dev/null 2>&1; then
    echo "✓ nonce是有效的Base64编码"
else
    echo "✗ nonce不是有效的Base64编码 (这是正常的，微信支付V3的nonce通常不是Base64编码)"
fi

# 检查API V3密钥长度
if [ ${#API_V3_KEY} -eq 32 ]; then
    echo "✓ API V3密钥长度正确 (32字符)"
else
    echo "✗ API V3密钥长度不正确 (当前: ${#API_V3_KEY}字符, 期望: 32字符)"
fi

echo ""
echo "运行Java解密测试..."

# 编译并运行Java测试
cd acdc
mvn compile exec:java -Dexec.mainClass="com.acdc.wechat.utils.WechatPayV3DecryptTester" -q

echo ""
echo "测试完成！"
